#pragma once

#include "CoordinateSys.h"

namespace ns_Position
{
    // 基准坐标系
    // 笛卡尔坐标系
    class CartesianCRD : public CoordinateSys
    {
    public:
        using PositonType = double;

    public:
        CartesianCRD()
        {}

        CartesianCRD(PositonType x, PositonType y, PositonType z)
            : _x(x),
              _y(y),
              _z(z)
        {}

        bool ToCartesianCRD(CartesianCRD* out) const override
        {
            out->_x = _x;
            out->_y = _y;
            out->_z = _z;

            return true;
        }

        bool FromCartesianCRD(const CartesianCRD& ref) override
        {
            _x = ref.GetX();
            _y = ref.GetY();
            _z = ref.GetZ();

            return true;
        }

        PositonType GetX() const
        {
            return _x;
        }

        PositonType GetY() const
        {
            return _y;
        }

        PositonType GetZ() const
        {
            return _z;
        }
    public:
        bool Encode(std::string* outJson) const override
        {
            Json::Value outValue;

            outValue["Type"] = "CartesianCRD";
            outValue["X"] = _x;
            outValue["Y"] = _y;
            outValue["Z"] = _z;

            Json::FastWriter writer;
            *outJson = writer.write(outValue);

            return true;
        }

        bool Decode(const std::string& inJson) override
        {
            Json::Value inValue;
			Json::Reader reader;
			bool parsingSuccessful = reader.parse(inJson, inValue);
			if (!(parsingSuccessful && inValue["Type"].asString() == "CartesianCRD"))
				return false;

            _x = inValue["X"].asDouble();
            _y = inValue["Y"].asDouble();
            _z = inValue["Z"].asDouble();

            return true;
        }
    private:
        PositonType _x;
        PositonType _y;
        PositonType _z;
    };
}